package com.eye.catcher.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eye.catcher.entity.TYwDaTemperatureHumidityInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 温湿度 表 Mapper 接口
 * </p>
 *
 * @author huzhiwei
 * @since 2022-05-12
 */
@Mapper
public interface TYwDaTemperatureHumidityInfoMapper extends BaseMapper<TYwDaTemperatureHumidityInfo> {
    String querySql = " select thi.*,fi.BASE_ID baseId,fi.BASE_CODE baseCode,fi.BASE_NAME baseName " +
            " from t_yw_da_temperature_humidity_info thi " +
            " left join t_yw_da_field_info fi on thi.FIELD_ID = fi.ID  " +
            " where (thi.FIELD_ID,thi.CREATE_TIME) in ( " +
            " select FIELD_ID,max(CREATE_TIME) from t_yw_da_temperature_humidity_info GROUP BY FIELD_ID " +
            " ) ";
    String wrapperSql = " select * from (" + querySql + ") as q ${ew.customSqlSegment}";
    String contWrapperSql = " select count(1) from (" + querySql + ") as q ${ew.customSqlSegment}";
    @Select(wrapperSql)
    List<TYwDaTemperatureHumidityInfo> list(@Param("ew") QueryWrapper<TYwDaTemperatureHumidityInfo> wrapper);
    @Select(wrapperSql)
    IPage<TYwDaTemperatureHumidityInfo> page(Page<TYwDaTemperatureHumidityInfo> page,@Param("ew") QueryWrapper<TYwDaTemperatureHumidityInfo> wrapper);

    @Select(contWrapperSql)
    long count(@Param("ew") QueryWrapper<TYwDaTemperatureHumidityInfo> wrapper);
}
